/**
 * Created by john on 2016/3/19.
 */
(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

//ajax
function ajax(url, dat, fn) {
    this.url = url;
    this.data = dat;
    $.ajax({
        url: this.url,
        type: "post",
        data: this.data,
        dataType: "json",
        success: function (data) {
            if (typeof(fn) == 'function') {
                fn(data)
            }
        }
    })
}


//消息回复

function msgReply(fn) {
    //回复
    var reply = $('.reply');
    var submit = $('.submit');
    reply.click(function () {
        reply.hide();
        submit.show();
    })

    //关闭回复框

    $('.close').click(function () {
        submit.hide();
        reply.show();
    })

    //提交信息
    var content_2 = $('.content_2');
    $('.tj').click(function () {
        var textarea = $('textarea');
        content_2.append(
            '<div class="info my">' +
            '<p>2016年03月23日  17:33:43</p>' +
            '<div class="news">' +
            '<div class="message bg">' +
            '<div class="bg"></div>' + textarea.val() +
            '</div>' +
            '<div class="portrait"><img src="../image/ceshi.png"/></div>' +
            '</div>' +
            '</div>'
        );
        if (typeof(fn) == 'function') {
            fn(textarea.val());
        }
        $(document).scrollTop($(document).height());
        submit.hide();
        reply.show();
        textarea.val('');
    })
}
